var mailList = new Array('@qq.com', '@163.com', '@126.com', '@sina.com', '@hotmail.com', '@gmail.com', '@sohu.com', '@yahoo.com', '@139.com');
$.fn.autoEmaile = function() {
    var $this = $(this)
    $this.bind("keyup", function () {
        var val = $(this).val();
        if (val == '' || val.indexOf("@") == -1) {
            $(".emaillist").hide();
            return false;
        }
        $('.emaillist').empty();
        for (var i = 0; i < mailList.length; i++) {
            var emailText = $(this).val();
            if (emailText.indexOf("@") != -1) {
                emailText = emailText.substring(0, emailText.indexOf("@"))
            }
            $('.emaillist').append('<li class=addr>' + emailText + mailList[i] + '</li>');
        }
        $('.emaillist').show();
        $('.emaillist li').click(function () {
            $this.val($(this).text());
            $('.emaillist').hide();
        })
    });

    $(document).on("click", function (e) {
        var target = $(e.target);
        if (target.attr("id") != "UserName") {
            $('.emaillist').hide();
        }
    });

    $this.on("blur", function (e) {
        setTimeout(function () {
            $('.emaillist').hide(); 
        }, 200);
    });
}

